import { showToast } from './index'
/**
 * @param(Object)
 */
export default (params) => {
  const baseUrl = 'http://bl.7yue.pro/v1/'
  const { url, method, data } = params
  return new Promise((resolve, reject) => {
    wx.request({
      url: `${baseUrl}${url}`,
      method,
      data,
      header: {
        'Content-Type': 'application/json',
        'appkey': 'keWR6ayobbmsBnkm'
      },
      success(res) {
        const { statusCode, data } = res
        if (String(statusCode).startsWith('2')) {
          // 代表成功
          resolve(data)
        } else {
          const { msg } = res.data
          showToast(msg, 'none')
          reject(res.data)
        }
      },
      fail(err) {
        showToast(err, 'none')
        reject(err)
      }
    })
  })
};
